﻿

    <!-- /PAGE HEADER -->
    <!-- FORMS -->
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-6">
                    <!-- BASIC -->
                    <div class="box border orange">
                        <div class="box-title">
                            <h4><i class="fa fa-bars"></i>新闻添加</h4>
                            <div class="tools hidden-xs">
                                <a href="#box-config" data-toggle="modal" class="config">
                                    <i class="fa fa-cog"></i>
                                </a>
                                <a href="javascript:;" class="reload">
                                    <i class="fa fa-refresh"></i>
                                </a>
                                <a href="javascript:;" class="collapse">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                                <a href="javascript:;" class="remove">
                                    <i class="fa fa-times"></i>
                                </a>
                            </div>
                        </div>
                        <div class="box-body big">




                            <form class="form-horizontal" action="" method="post" role="form"  enctype="multipart/form-data">


                              <div class="form-group">
                                <label for="inputPassword3" class="col-sm-2 control-label">分类名称</label>
                                <div class="col-sm-10">
                                  <input type="text" name="name" class="form-control" id="inputPassword3" placeholder="请输入标题">
                                </div>
                              </div>

                              <div class="form-group">
                                <label for="inputPassword2" class="col-sm-2 control-label">分类归属</label>
                                <div class="col-sm-2 list">
                                  <select class="form-control select_cate"  name="pid">
                                        <option value="0">顶级分类</option>
                                       <?php foreach($cate as $value){?>
                                       <option value="<?php echo $value['id']?>"><?php echo $value['name']?></option>
                                       <?php }?>
                                      </select>
                                </div>
                              </div>

                              <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                  <button type="submit" class="btn btn-pink">提交</button>
                                </div>
                              </div>
                            </form>

                        </div>
                    </div>
                                        <!-- /BASIC -->
                                        <!-- BASIC -->
  <script src="resources/admin/js/jquery/jquery-2.0.3.min.js""></script>
 <script type="text/javascript">
        $(function(){
            $('.list').on('change','select',function(){


                    //选中项id值
                 var id = $(this).val();
                   //删除当前操作之后的所有select标签

                 $(this).nextAll().remove();
                    //选中的是上一级则终止程序执行
                 if($(this).get(0).selectedIndex==0){
                       return false;
                 }

                 //通过ajax获取选中项的子级数据
                 $.ajax({
                    type:'get',
                    url:'index.php?c=cate&a=add&admin=1&id='+id,
                    dataType:'json',
                    success:function(json){
          // alert(1);
                      //将程序返回子级的数据显示在下拉列表中
                      var html='';
                        html+='<select class="form-control" name="pid">';
                        html+='<option value="'+id+'">上一级</option>';

                        for(i in json){
                             html+='<option value="'+json[i].id+'">'+json[i].name+'</option>';
                        }
                        html+='</select>';

                          //将新的下拉列表追加到原来的下拉列表后面
                        $('.list').append(html);
                    }

                 })
              })
        })


 </script>

